package demo.cometProcessor;

import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.apache.catalina.comet.CometEvent;
import org.apache.catalina.comet.CometEvent.EventType;
import org.apache.catalina.comet.CometProcessor;

/**
 * @author levy.xia
 * 
 */
public class CometServlet extends HttpServlet implements CometProcessor {

	private static final long serialVersionUID = 1L;

	public void event(CometEvent e) throws IOException, ServletException {
		if (e.getEventType() == EventType.BEGIN) {
			// fill in code handling here
			HttpServletResponse response = e.getHttpServletResponse();
			PrintWriter out = response.getWriter();
			out.write("Hello world");
			out.flush();
			// System.out.println("message sent");
		}
		if (e.getEventType() == EventType.READ) {
			// fill in code handling here
		}
		// and continue handing other events
	}
}